﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DataTier;
using DataAccessLayer;

namespace BusinessTier
{
    public class BCustomer : IBCustomer
    {
        public Customer customerLogin(string email, string password)
        {
           Customer customer = null;

            if(DBCustomer.GetCustomerByEmail(email).Password == password)
            {
                customer = DBCustomer.GetCustomerByEmail(email);
            }
            
            customer.Subscriptions = DBSubscription.GetSubscriptions(customer.CustomerId);
            foreach(Subscription subscription in customer.Subscriptions)
            {
                subscription.SubscriptionType = DBSubscription.GetSubType(subscription.SubscriptionId);
                //needs a method in DB to get a carmodel
                //need a method in DB to get the battery for each sub
            }



            return customer;
           
        }

        public List<Subscription> GetSubscriptions(int customerId)
        {
            throw new NotImplementedException();
        }

        public IList<Customer> GetAllCustomers()
        {
            return DBCustomer.GetCustomers();
        }

        public void DeleteCustomerById(int id)
        {
            DBCustomer.DeleteCustomerById(id);
        }

        public void UpdateCustomer(int id, string uName, string name, string address, int zip, string email, string password)
        {
            DBCustomer.UpdateCustomer(id, uName, name, address, zip, email, password);
        }



        public void CreateCustomer(string uName, string name, string address, int zip, string email, string password)
        {
            DBCustomer.CreateCustomer(uName, name, address, zip, email, password);
        }

        public string GetCityFromZip(int zip)
        {
            return DBCustomer.GetCityFromZip(zip);
        }


        public Customer GetCustomerByUserName(string username)
        {
            return DBCustomer.GetCustomerByUserName(username);
        }
    }

}
